-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8346195: Fix static initialization problem in GDIHashtable #22736
Conversation
👋 Welcome back ihse! A progress list of the required criteria for merging this PR into |
@magicus This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 64 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Any reviewers on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reviewers on this?
Looks ok and trivial to me (But I'm not a Reviewer, unfortunately)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if this is already on my list of reasons I don't like C++.
/integrate |
Going to push as commit 03821d9.
Your commit was automatically rebased without conflicts. |
I did not know about this until I tried to resolve this bug (it took some time to figure out the problem). I can surely put it on my such list. :) |
There has been a latent problem in
GDIHashtable
since time immemorial, but due to sheer luck it has not caused any issues for us. However, I managed to provoke it when I was doing some build changes.This is the problem:
In
GDIHashtable
, there is a static fieldGDIHashtable::BatchDestructionManager manager
, which is initialized inGDIHashtable.cpp
.In
AwtPen
, there is a static fieldGDIHashtable cache
, which is initialized inawt_Pen.cpp
.The
GDIHashtable
constructor callsmanager.add(this)
.For this to work, the manager must have been initialized prior to the AwtPen. However, the order of which static initializers are run between different compilation units are not well-defined, and we've just been lucky so far that it works.
This problem is known as the "Static Initialization Order Fiasco", see e.g. https://en.cppreference.com/w/cpp/language/siof
I have solved this by encapsulating the static manager instance in a method, which guarantees that it has been initialized before use. This seemed to me to be the cleanest solution.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/22736/head:pull/22736
$ git checkout pull/22736
Update a local copy of the PR:
$ git checkout pull/22736
$ git pull https://git.openjdk.org/jdk.git pull/22736/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 22736
View PR using the GUI difftool:
$ git pr show -t 22736
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/22736.diff
Using Webrev
Link to Webrev Comment